<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="跟踪单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'trackNo', validatorRules.trackNo]" placeholder="请输入跟踪单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'headline', validatorRules.headline]" placeholder="请输入标题"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'empname', validatorRules.empname]" placeholder="请输入申请人"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'itemNo', validatorRules.itemNo]" placeholder="请输入项目编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="申请表编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'applicationForm', validatorRules.applicationForm]" placeholder="请输入申请表编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'applyDptname', validatorRules.applyDptname]" placeholder="请输入申请部门"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'itemName', validatorRules.itemName]" placeholder="请输入项目名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['mtype', validatorRules.mtype]" :trigger-change="true" dictCode="mes_mtype" placeholder="请选择产品类型"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="项目经理" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'projectEmpname', validatorRules.projectEmpname]" placeholder="请输入项目经理"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品经理" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'productEmpname', validatorRules.productEmpname]" placeholder="请输入产品经理"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="源文件编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'sourceFileNo', validatorRules.sourceFileNo]" placeholder="请输入源文件编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="验证类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['verifyType', validatorRules.verifyType]" :trigger-change="true" dictCode="mes_check_type" placeholder="请选择验证类型"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="验证轮次" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'verifyTimes', validatorRules.verifyTimes]" placeholder="请输入验证轮次" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="验证方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['verifyManner', validatorRules.verifyManner]" :trigger-change="true" dictCode="mes_check_method" placeholder="请选择验证方式"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="机型数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'qty', validatorRules.qty]" placeholder="请输入机型数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="产品异常反馈单" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'anomalyForm', validatorRules.anomalyForm]" placeholder="请输入产品异常反馈单"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="锁定范围" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'lockRange', validatorRules.lockRange]" placeholder="请输入锁定范围"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="是否提前退出" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['dropOut', validatorRules.dropOut]" :trigger-change="true" dictCode="ba_yn" placeholder="请选择是否提前退出"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="跟踪单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['trackNoStatus', validatorRules.trackNoStatus]" :trigger-change="true" dictCode="mes_track_no_status" placeholder="请选择跟踪单状态"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="创建类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['createType', validatorRules.createType]" :trigger-change="true" dictCode="mes_create_type" placeholder="请选择创建类型"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="待处理人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'handleEmpname', validatorRules.handleEmpname]" placeholder="请输入待处理人员"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="跟踪单类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['tcType', validatorRules.tcType]" :trigger-change="true" dictCode="mes_tc_order_type" placeholder="请选择跟踪单类型"/>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction, putAction, api } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesPeTrackListBasicinfoModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        trackNo:{rules: [{ required: true, message: '请输入跟踪单号!' }]},
        headline:{rules: [{ required: true, message: '请输入标题!' }]},
        empname:{rules: [{ required: true, message: '请输入申请人!' }]},
        itemNo:{rules: [{ required: true, message: '请输入项目编号!' }]},
        applicationForm:{rules: [{ required: true, message: '请输入申请表编号!' }]},
        applyDptname:{rules: [{ required: true, message: '请输入申请部门!' }]},
        itemName:{rules: [{ required: true, message: '请输入项目名称!' }]},
        mtype:{rules: [{ required: true, message: '请输入产品类型!' }]},
        projectEmpname:{rules: [{ required: true, message: '请输入项目经理!' }]},
        productEmpname:{rules: [{ required: true, message: '请输入产品经理!' }]},
        sourceFileNo:{rules: [{ required: true, message: '请输入源文件编号!' }]},
        verifyType:{rules: [{ required: true, message: '请输入验证类型!' }]},
        verifyTimes:{rules: [{ required: true, message: '请输入验证轮次!' }]},
        verifyManner:{rules: [{ required: true, message: '请输入验证方式!' }]},
        qty:{rules: [{ required: true, message: '请输入机型数量!' }]},
        anomalyForm:{rules: [{ required: true, message: '请输入产品异常反馈单!' }]},
        lockRange:{rules: [{ required: true, message: '请输入锁定范围!' }]},
        dropOut:{rules: [{ required: true, message: '请输入是否提前退出!' }]},
        trackNoStatus:{rules: [{ required: true, message: '请输入跟踪单状态!' }]},
        createType:{rules: [{ required: true, message: '请输入创建类型!' }]},
        handleEmpname:{rules: [{ required: true, message: '请输入待处理人员!' }]},
        tcType:{},
        },
        url: {
          add: '/mes-craft/auto/mesPeTrackListBasicinfo/add',
          edit: '/mes-craft/auto/mesPeTrackListBasicinfo/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
        this.getRuleCodeValue();
      },
      getRuleCodeValue() {
        let param = {
          commonFormData: this.model,
          rules: [
            {"ruleCode": "mes_track_no", "columnName": "trackNo"},
            ]
        }

        putAction(api.ruleBaseURL, param).then(res => {
          // 执行成功，获取返回的值，并赋到页面上
          if (res.success) {
            console.log("生成的编码：" + res.data)
            const item = res.data;
            this.form.setFieldsValue(pick(item, Object.keys(item)))
          }
        })
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'trackNo','headline','empname','itemNo','applicationForm','applyDptname','itemName','mtype','projectEmpname','productEmpname','sourceFileNo','verifyType','verifyTimes','verifyManner','qty','anomalyForm','lockRange','dropOut','trackNoStatus','createType','handleEmpname','tcType','createBy','createTime','updateBy','updateTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'trackNo','headline','empname','itemNo','applicationForm','applyDptname','itemName','mtype','projectEmpname','productEmpname','sourceFileNo','verifyType','verifyTimes','verifyManner','qty','anomalyForm','lockRange','dropOut','trackNoStatus','createType','handleEmpname','tcType','createBy','createTime','updateBy','updateTime'))
      },

      
    }
  }
</script>
